<?php

namespace App\Admin\Controllers\system;

use App\Admin\Repositories\System\SystemLevel;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class SystemLevelController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SystemLevel(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('icon')->image();
            $grid->column('name')->width('80px');
            $grid->column('grade');
            $grid->column('discount');
            $grid->column('valid_date');
            $grid->column('is_forever')->switch();
            $grid->column('is_show')->switch();
            $grid->column('image')->image();
            $grid->column('explain');
            $grid->column('created_at');
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SystemLevel(), function (Show $show) {
            $show->field('id');
            $show->field('icon');
            $show->field('name');
            $show->field('grade');
            $show->field('discount');
            $show->field('valid_date');
            $show->field('is_forever');
            $show->field('explain');
            $show->field('mer_id');
            $show->field('money');
            $show->field('is_pay');
            $show->field('is_show');
            $show->field('image');

            $show->field('is_del');
            $show->field('created_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SystemLevel(), function (Form $form) {
            $form->display('id');
            $form->text('mer_id');
            $form->text('name');
            $form->decimal('money');
            $form->text('valid_date');
            $form->radio('is_forever')->options(['1'=>'永久','2'=>'限时'])->default('1');
            $form->radio('is_pay')->options(['1'=>'购买','0'=>'不购卖'])->default('1');
            $form->radio('is_show')->options(['1'=>'显示','0'=>'隐藏'])->default('1');
            $form->number('grade')->min(0);
            $form->decimal('discount');
            $form->image('image');
            $form->image('icon');
            $form->textarea('explain')->rows(5);
            $form->radio('is_del')->options(['1'=>'删除','0'=>'未删除'])->default('1');
            $form->display('created_at');
        });
    }
}
